﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bluyel.Core
{
    /// <summary>
    /// Factory to build DataValue.
    /// </summary>
    public class FactoryValue
    {
        //=====================================================================
        #region Constructor.

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        public FactoryValue()
        {

        }

        #endregion

        //=====================================================================
        #region Public Create DVal TypeBasic methods.

        //---------------------------------------------------------------------
        /// <summary>
        /// Create a (empty) data value, set the type.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public IValueBasic CreateValue(ITypeBasic type)
        {
            if (type == null)
                return null;

            if (type.Name.Equals(TypeDef.TypeBoolName))
                return new ValueBool();
            if (type.Name.Equals(TypeDef.TypeStringName))
                return new ValueString();
            if (type.Name.Equals(TypeDef.TypeIntName))
                return new ValueInt();
            if (type.Name.Equals(TypeDef.TypeDoubleName))
                return new ValueDouble();

            // if its a void type, cant create a data
            return null;
        }


        //---------------------------------------------------------------------
        /// <summary>
        /// Create an int value.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ValueInt CreateValueInt(int val)
        {
            return new ValueInt(val);
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Create a long value.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ValueLong CreateValueLong(long val)
        {
            return new ValueLong(val);
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// Create a double data value.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ValueDouble CreateValueDouble(double val)
        {
            return new ValueDouble(val);
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// Create a string data value.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ValueString CreateValueString(string val)
        {
            // ok the type string is defined
            return new ValueString(val);
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Create a bool data value.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ValueBool CreateValueBool(bool val)
        {
            return new ValueBool(val);
        }

                #endregion

        //=====================================================================
        #region Public Create DVal TypePhysQty methods.

        //---------------------------------------------------------------------
        /// <summary>
        /// Create a data value Physical qty, subType can be: Length.
        /// </summary>
        /// <param name="typePhysQty"></param>
        /// <returns></returns>
        public IValuePhy CreateValue(ITypePhy typePhysQty)
        {
            if (typePhysQty == null)
                return null;

            if (typePhysQty.Id.IdAreEquals(TypeDef.TypePhyLengthId))
                return new ValuePhyLength();

            // type not yet implemented!
            return null;
        }

        #endregion
    }
}
